package com.platform.modules.wallet.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.platform.common.web.service.impl.BaseServiceImpl;
import com.platform.modules.wallet.dao.WalletConfigDao;
import com.platform.modules.wallet.domain.WalletConfig;
import com.platform.modules.wallet.service.WalletConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;

@Slf4j
@Service("walletConfigService")
public class WalletConfigServiceImpl extends BaseServiceImpl<WalletConfig> implements WalletConfigService {

    @Resource
    private WalletConfigDao walletConfigDao;

    @Autowired
    public void setBaseDao() {
        super.setBaseDao(walletConfigDao);
    }

    @Override
    public WalletConfig getByKey(String key) {
        return new WalletConfig().selectOne(new LambdaQueryWrapper<WalletConfig>().eq(WalletConfig::getConfigKey, key));
    }

    @Override
    public String[] getServiceKefu() {
        WalletConfig config = new WalletConfig().selectOne(new LambdaQueryWrapper<WalletConfig>()
                .eq(WalletConfig::getConfigKey, "service"));
        if (ObjectUtil.isEmpty(config) || StrUtil.isBlank(config.getValue())) return new String[0];

        return config.getValue().split(",");
    }

//    @Override
//    public String[] getLongTerm() {
//        WalletConfig config = new WalletConfig().selectOne(new LambdaQueryWrapper<WalletConfig>()
//                .eq(WalletConfig::getConfigKey, "longTerm"));
//
//        if (ObjectUtil.isEmpty(config) || StrUtil.isBlank(config.getValue())) return new String[0];
//
//        return config.getValue().split(",");
//    }
}
